<!--
 * @Author: 莫莫
 * @Phone: 13450159681
 * @Description: 
 * @Date: 2024-11-19 15:25:02
 * @LastEditTime: 2024-12-18 19:47:33
-->
<template>
	<view class="user" style="background-image: url('/static/image/user_bg.png');">
		<view class="f60 title fb tc">90度家居</view>
		<view class="btn mt80">
			<up-button text="快捷登录" color="#000" shape="circle" size="large" @click="login"></up-button>
		</view>
		<label class="radio mt45 tc f28 d-c-c">
			<radio value="" class="mr10" />我已阅读并同意<text>《用户协议》</text><text>《隐私协议》</text>
		</label>
	</view>
</template>

<script setup>
import { reactive } from 'vue'
import { onLoad } from "@dcloudio/uni-app";
import { useStore } from "vuex"
const store = useStore()
const data = reactive({

})
async function login() {
	let codeStr = '';
	const loginResult = await uni.login();
	if (loginResult.errMsg === 'login:ok') {
		codeStr = loginResult.code;
	} else {
		// getSessionId(auto_login);
		return false;
	}
	const { code, data } = await store.dispatch('request', {
		url: store.state.api.third.wechat.getSessionId,
		data: {
			platform: 'miniProgram',
			payload: encodeURIComponent(
				JSON.stringify({
					code: codeStr,
					auto_login: true,
				}),
			),
		}
	})
	if (code === 1) {
		uni.setStorageSync('sessionId', data.session_id); 
	}

	const res = await store.dispatch('request', {
		url: store.state.api.third.wechat.login,
		data: {
			platform: 'miniProgram',
			payload: encodeURIComponent(
				JSON.stringify({
					sessionId: uni.getStorageSync('sessionId'),
				}),
			),
		}
	})
	if (res.code === 1) {
		uni.navigateBack()
		return true;
	}


}

</script>

<style scoped lang="scss">
.radio {
	text {
		color: #E9C99A;
	}
}

.btn {
	width: 500rpx;
	margin-left: auto;
	margin-right: auto;
}

.user {
	min-height: 100vh;
	width: 100%;
	background-position: top center;
	background-repeat: no-repeat;
	background-size: contain;
	padding-top: 195rpx;
	background-color: #f6f6f6;
}

.title {
	color: #EEB663;
}
</style>